SolverOk Function

Defines a basic Solver model. Equivalent to clicking Solver on the Tools menu and then specifying options in the Solver Parameters dialog box.

Before you use this function, you must establish a reference to the Solver add-in. With a Visual Basic module active, click References on the Tools menu, and then select the Solver.xla check box under Available References. If Solver.xla doesn't appear under Available References, click Browse and open Solver.xla in the \Office\Library\Solver\ subfolder.

SolverOk(SetCell, MaxMinVal, ValueOf, ByChange)

SetCell    Optional Variant. Refers to a single cell on the active worksheet. Corresponds to the Set Target Cell box in the Solver Parameters dialog box.

MaxMinVal    Optional Variant. Corresponds to the Max, Min, and Value options in the Solver Parameters dialog box.

MaxMinVal Specifies
1 Maximize.
2 Minimize.
3 Match a specific value.

ValueOf    Optional Variant. If MaxMinVal is 3, you must specify the value to which the target cell is matched.

ByChange    Optional Variant. The cell or range of cells that will be changed so that you’ll obtain the desired result in the target cell. Corresponds to the By Changing Cells box in the Solver Parameters dialog box.

Example

This example uses the Solver functions to maximize gross profit in a business problem. The SolverOK function defines a problem by specifying the SetCell, MaxMinVal, and ByChange arguments.

Worksheets("Sheet1").Activate
SolverReset
SolverOptions precision:=0.001
SolverOK SetCell:=Range("TotalProfit"), _
    MaxMinVal:=1, _
    ByChange:=Range("C4:E6")
SolverAdd CellRef:=Range("F4:F6"), _
    Relation:=1, _
    FormulaText:=100
SolverAdd CellRef:=Range("C4:E6"), _
    Relation:=3, _
    FormulaText:=0
SolverAdd CellRef:=Range("C4:E6"), _
    Relation:=4
SolverSolve UserFinish:=False
SolverSave SaveArea:=Range("A33")